using System;
using System.Collections.Generic;
using Entitas;

public sealed class DestroyEntitySystem : ReactiveSystem {


    readonly Contexts _contexts;

    public DestroyEntitySystem(Contexts contexts) : base(contexts.core)
    {
        _contexts = contexts;
    }


    protected override void Execute(List<Entity> entities) {
        foreach(var e in entities) {
            foreach(var pool in _contexts.allContexts) {
                if(pool.HasEntity(e)) {
                    pool.DestroyEntity(e);
                    break;
                }
            }
        }
    }

    protected override Collector GetTrigger(Context context)
    {
        return context.CreateCollector(Matcher.AnyOf(CoreMatcher.Destroy, CoreMatcher.OutOfScreen));
    }

    protected override bool Filter(Entity entity)
    {
        return true;
    }
}
